package com.yn.xr.middleware.news.rmi.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yn.xr.common.page.Page;
import com.yn.xr.middleware.news.rmi.NewsInfoRmiService;
import com.yn.xr.middleware.news.service.NewsCommentService;
import com.yn.xr.middleware.news.service.NewsInfoService;
import com.yn.xr.news.mode.NewsComment;
import com.yn.xr.news.mode.NewsInfo;

@Service("newsInfoRmiService")
@Transactional
public class NewsInfoRmiServiceImpl implements NewsInfoRmiService {

	private static final Logger logger = LoggerFactory
			.getLogger(NewsInfoRmiServiceImpl.class);

	@Resource
	private NewsInfoService newsInfoService; // 新闻操作service
	
	@Resource
	private NewsCommentService newsCommentService; // 回复

	@Override
	public NewsInfo queryNewsInfoById(Integer newsId) throws Exception {
		return newsInfoService.queryNewsInfoById(newsId);
	}

	@Override
	public Page<NewsInfo> queryNewsInfoPage(String hql, Object[] queryParams, int pageNum, int pageSize) throws Exception {
		return newsInfoService.page( pageNum , pageSize, hql, queryParams);
	}

	@Override
	public void saveNewsInfo(NewsInfo newsInfo) throws Exception {
		if( newsInfo != null ){
			newsInfoService.save(newsInfo);
		}
	}

	@Override
	public void editNewsInfo(NewsInfo newsInfo) throws Exception {
		newsInfoService.update(newsInfo);
	}

	@Override
	public void deleteNewsInfo(Integer newsId) throws Exception {
			// 删除新闻的时候，同步删除新闻相关的回复及新闻相关的评论；
			//newsCommentService.deleteNewsCommentBynewsId(newsId);
			//commentRevertService.deleteNewsCommentRevertBynewsId(newsId);
			//+newsInfoService.delete(newsId);
	}

	@Override
	public Page<NewsInfo> queryNewsInfoRecommendPage(NewsInfo newsInfo,
			int pageNum, int pageSize) throws Exception {
		Page<NewsInfo> page = null;
		try {
			page = newsInfoService.queryNewsInfoRecommendTimePage(
					newsInfo, pageNum, pageSize);
		} catch (Exception e) {
			logger.error("分页获取新闻集合根据推荐时间排序异常，异常信息：", e);
		}
		return page;
	}


	@Override
	public List<NewsInfo> getNewsInfoHeatRank(Integer number, Integer platform,
			Integer type) throws Exception {
		return newsInfoService
				.queryNewsInfoHeatRankList(number, platform, type);
	}

	@Override
	public NewsInfo getNewsInfoNext(Integer newsId, Integer type,
			Integer platformId) throws Exception {
		return newsInfoService.queryNewsInfoNext(newsId, type, platformId);
	}

	@Override
	public NewsInfo getNewsInfoPrev(Integer newsId, Integer type,
			Integer platformId) throws Exception {
		return newsInfoService.queryNewsInfoPrev(newsId, type, platformId);
	}

	@Override
	public int updaBrowseNumber(NewsInfo newsInfo) throws Exception {
		return newsInfoService.updateBrowseNumber(newsInfo);
	}

	@Override
	public Page<NewsInfo> queryOtherNewsInfoPage(NewsInfo newsInfo,
			Integer pageNum, Integer pageSize, String newsId,
			String pageUpnewsId, String nextNewsId) throws Exception {
		return newsInfoService.queryOtherNewsInfoPage(newsInfo, pageNum,
				pageSize, newsId, pageUpnewsId, nextNewsId);
	}

	@Override
	public void publishNewsInfo(Integer... newsId) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void cancelPublishNewsInfo(Integer... newsId) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void recommendNewsInfo(Integer... newsId) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void cancelRecommendNewsInfo(Integer... newsId) throws Exception {
		// TODO Auto-generated method stub
		
	}
	
	/**
     * @Description: 添加新闻评论或者评论回复
     * @author wangpinwen
     * @date 2015年9月5日 下午10:15:36 
     * @version V1.0.0
     * @param newsComment
     * @throws Exception
     */
	public void addCommentOrRevert(NewsComment newsComment ) throws Exception{
		newsCommentService.saveNewsComment(newsComment);
	}
	
	public Page<NewsComment> queryCommentPage(String hql ,Object[] queryParams , int pageNum, int pageSize ) throws Exception{
		return newsCommentService.page( pageNum , pageSize, hql, queryParams);
	}
}
